<template>
  <div>
    <el-image-viewer v-if="showViewer" :url-list="url" />
  </div>
</template>

<script setup>
const { proxy } = getCurrentInstance();

const showViewer = ref(false);
const url = ref("");

const props = defineProps({
  // 数据
  list: {
    type: Array,
  },
  isShare: {
    type: Boolean,
    default: true
  },
});

watch(
  () => props.list,
  (val) => {
    if (val.length) {
      imageView();
    }
  }
);

const emit = defineEmits(["close"]);

function imageView() {
  proxy.$modal.loading("正在获取图片，请稍候...");
  url.value = [];
  props.list.forEach((item, index) => {
    eval("proxy.$download." + (props.isShare?"previewSharePicById":"previewPicById"))(item.fileId).then((resp) => {
      url.value.push(resp);
      if (index == url.value.length - 1) {
        proxy.$modal.closeLoading();
        showViewer.value = true;
        nextTick(() => {
          $(".el-image-viewer__close").click(function () {
            emit("close");
            showViewer.value = false;
          });
        });
      }
    });
  });
}
</script>

<style scoped></style>
